package com.chinanet.repository.manager;

import com.chinanet.entry.manager.Amend;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;

/**
 * @RepositoryRestResource(collectionResourceRel = "amend", path = "amend")
 * 默认添加,即不用写Contorller,也会实现符合Rest Api规范的方法
 */
public interface AmendRepository extends PagingAndSortingRepository<Amend, Long> {
    @RestResource(path = "version",rel = "version")
    @Query(value = "select * from amend where version_id=:versionId", nativeQuery = true)
    Page<Amend> getAllByVersion(@Param("versionId") long versionId, Pageable pageable);

    @RestResource(path = "notVersion",rel = "not/version")
    @Query(value = "select * from amend where version_id<>:versionId or version_id is null", nativeQuery = true)
    Page<Amend> getAllNotByVersion(@Param("versionId") long versionId, Pageable pageable);

}